<?php
$isReloadable = true;
require_once("../../pers/inc.config.php");
require_once(OVF_FS_WEB_ROOT.'/app/_inc/inc.session.php');
require_once(OVF_FS_WEB_ROOT.'/app/_inc/funct.html.php');
require_once(OVF_FS_WEB_ROOT.'/app/gest/util/_inc/funct.confDb.php');

reqDef('pag_iniz', $objSess->pagIniz);

switch (reqVar('azione')) {
	case 'cambia' :
		$msgPag = cambia();
		break;
	case 'aggnews' :
		foreach($objSess->aRssUrl as $dX => $urlX) {
			ovfScriviRss($urlX);
		}
		header("location: opzPers.php?msgbck=".urlencode(_t('aggiornate news'))."&$sXSNQS");
		break;
	case 'rescron' :
		$objSess->resetHistory();
		$msgPag .= _t('cronologia azzerata');
		break;
}

$sCmdL  = "";
$sCmdL .=  "<a class='cmd1' href='opzPers.php?azione=aggnews&$sXSNQS'>"._t("aggiorna news")."</a>\n";
$sCmdL .= "&nbsp;&nbsp;&nbsp";
$sCmdL .=  "<a class='cmd1' href='opzPers.php?azione=rescron&$sXSNQS'>"._t("reset cronologia")."</a>\n";

$sCmdR  = "&nbsp;&nbsp;&nbsp";
$sCmdR .=  "<a class='cmd1' href='javascript:document.frm1.submit();'>"._t("salva")."</a>\n";
$sCmdR .=  cmdTorna();

require OVF_FS_WEB_ROOT."/app/gest/uten/_inc/const.aPagIniz.php";

testaHtml('Opzioni personali', 'Preferenze',$msgPag, 'opzp');
?>
<table border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
   <tr>
      <td class="cmd1" align="left" valign='bottom'>
         <? echo $sCmdL;?>
      </td>
      <td class="cmd1" align="right" valign='bottom'>
         <? echo $sCmdR;?>
      </td>
   </tr>
</table>
<form name='frm1' action='<?=$_SERVER['PHP_SELF']?>' method='post' enctype="multipart/form-data">
<input type='hidden' name='azione' value="cambia">
<input type='hidden' name='xsn' value="<?=XSN?>">
<table class="tab1" border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
<?echo getHtmlRigaRif(20);?>
	<tr>
		<td class="lab1" colspan='4'>
			<?=_t("Pagina iniziale")?>
		</td>
		<td class="txt1" colspan='16'>
			<?php echo getHtmlSelect('pag_iniz',$aPagIniz)?>
		</td>
	</tr>
	<tr>
		<td class="lab1" colspan='20'><?=_t('Selezione NEWS');?></td>
	</tr>
	<tr>
		<td class="txt1" colspan='20'>
<?
$sSql = "SELECT r.*, ur.id_utente FROM ovf_rss_url r "
	." LEFT JOIN ovf_utenti_rss ur ON ur.id_rss = r.id_rss "
	."    AND ur.id_utente = ".$objSess->idUtente
	." ORDER BY descr";
$objDB->query($sSql,'selRssUt');
while($acX = $objDB->fetch('selRssUt')) {
?>
			<?
			reqDef('cb_rss_'.$acX['id_rss'],($acX['id_utente']>0)?'S':'');
			echo getHtmlCheckBox('cb_rss_'.$acX['id_rss'], 'S');
			echo "&nbsp;";
			echo $acX['descr'];
			echo "<br/>";
			?>
<?
}
?>
		</td>
	</tr>
</table>
</form>
<table border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
   <tr>
      <td class="cmd1" align="left" valign='bottom'>
         <? echo $sCmdL;?>
      </td>
      <td class="cmd1" align="right" valign='bottom'>
         <? echo $sCmdR;?>
      </td>
   </tr>
</table>
<?
codaHtml();
exit();

function cambia() {
	global $objDB,$objSess;
	$msg = '';
	$sSql = "UPDATE ovf_utenti SET pag_iniz = '".reqVarAS('pag_iniz')
		."' WHERE id_utente = ".intval($objSess->idUtente);
	$objDB->query($sSql,'selUten');
	 $objSess->pagIniz = reqVar('pag_iniz');
	$sSql = "DELETE FROM ovf_utenti_rss WHERE id_utente = ".intval($objSess->idUtente);
	$objDB->query($sSql,'selUten');
	foreach($_REQUEST as $nX => $vX) {
		if (substr($nX,0,7)!='cb_rss_') continue;
		$idX = substr($nX,7);
		$sSql = "INSERT ovf_utenti_rss SET id_rss = $idX, id_utente = ".intval($objSess->idUtente);
		$objDB->query($sSql,'selUten');
	}
	$objSess->setRssUrl();
	return _t("preferenze registrate");
}